package org.example.myleet.rosalind.splc;

import org.example.myleet.rosalind.prot.RnaTranslator;
import org.example.myleet.rosalind.utils.FastaReader;
import org.example.myleet.rosalind.utils.FastaSequence;

import java.util.List;

public class Solution {

    private static final RnaTranslator RNA_TRANSLATOR = new RnaTranslator();

    public static void main(String[] args) {
        Solution solution = new Solution();
//        solution.printTranslatedPeptide(">Rosalind_10\n" +
//                "ATGGTCTACATAGCTGACAAACAGCACGTAGCAATCGGTCGAATCTCGAGAGGCATATGGTCACATGATCGGTCGAGCGTGTTTCAAAGTTTGCGCCTAG\n" +
//                ">Rosalind_12\n" +
//                "ATCGGTCGAA\n" +
//                ">Rosalind_15\n" +
//                "ATCGGTCGAGCGTGT\n");
        solution.printTranslatedPeptide(">Rosalind_5110\n" +
                "ATGTTCCTATTACATAGCGGTGGCTCGTTGCGTGGACCATAAATAAACAGTGGCACGCTG\n" +
                "GTCTTGTGGGGGCTCTAGATGAGTTCTCCGATACCTCATCGTCATGATTTGACGGGTTCA\n" +
                "TCAAGATTGTCAGATGATCATGTCCATAACTCAGGTATACTTGGCATATAAGGACTTGTT\n" +
                "CTATACATCAGGTATCGTCCACATCAACTATTAGCGATAAGTCATATTAAACTTACATTC\n" +
                "ACGGCGTTGTAACAACCCTGAACTCTTCTACCATTCAAGTTGGCTGTTTTTGAATCGAAG\n" +
                "ATAAAACAGAGTCTACCAACCCCGGACTATGGATGTGATAGCCACTGTGTGTTGCGTCGC\n" +
                "CAAGCTGACTTGCTCGTGGCTCCCGGAAGAGCGTTCTATTAAGCCCTAAAAAGGGGTGTC\n" +
                "ATTAGCGTGAATCGGCAACCTACCAATCATAACTGGCACTACCGCGCCCAGTCGATTTGG\n" +
                "GAACCACATAGGCACATCCCGCCCCGATTTGGAGCTATGGGTTACGGTGGCCTCCCTAAG\n" +
                "TAGCCCAATAAGCGAGTGTCTAGCAAACTCTCTGATCTATCACGTGTCCGTATTCCTTGG\n" +
                "CTTCCGGTGTCGTATTACGGACTACTCGCCTCTGTAAGCGAAGGCGTTCTCATGAAGTTT\n" +
                "AGCAGATCATACACTGCGGGCACGCAAACTTTGTTTCCTAAATGACAAAGTGATCGGCGA\n" +
                "GAACAAATGCTGGCCGTGCACATGCCGCTTGGAATGGGTATGAAATACGTCAGGTCTTGA\n" +
                "TATGATGCCTTCACAGGACTTTGTCTCAAGTCGTCCAATATCGGTGAATTCATTGGTTCG\n" +
                "GTGGCTATGTTTCTCATTTTCCGTACCTAACCACGCGTAGTGAGCCCTTAGCGTTGTCGT\n" +
                "CACCAAGCCGACCCATCTTCATGCGACGCAGAGATAGAACCCAAATTCTCTACGGCTTAC\n" +
                "CGGGATGCCATCCAAGGCATGA\n" +
                ">Rosalind_0197\n" +
                "TCGGTGGCTATGTTTCT\n" +
                ">Rosalind_1646\n" +
                "GGCTTCCGGTGTCGTATTACGGACTACTCGCCTCTGTAAGCGAAGGC\n" +
                ">Rosalind_6586\n" +
                "CCTGAACTCTTCTACCATTCAAGTTGGCTGTT\n" +
                ">Rosalind_2609\n" +
                "CCAACCCCGGACTATGGA\n" +
                ">Rosalind_4156\n" +
                "ATGGGTTACGGTGGCCTCCCTAAGTAGCCCAATAAGCGAGTGTCTAGCA\n" +
                ">Rosalind_2738\n" +
                "GATCATGTCCATAACTCAGGTATACTTGG\n" +
                ">Rosalind_9495\n" +
                "CGGCAACCTACCAATC\n" +
                ">Rosalind_0015\n" +
                "GTATGAAATACGTCAGGTCTTGATATGATGCC\n" +
                ">Rosalind_1876\n" +
                "TCGTCCACATCAACTATTAGCGATAAGTC\n" +
                ">Rosalind_9455\n" +
                "GGTGGCTCGTTGCGTGGACCATAAATAAACAGTGGCACGCT\n" +
                ">Rosalind_9818\n" +
                "ATCTTCATGCGACGCAGAGATAG\n" +
                ">Rosalind_6865\n" +
                "ACTGCGGGCACGCAAA\n" +
                ">Rosalind_1324\n" +
                "GCGCCCAGTCG\n" +
                ">Rosalind_3868\n" +
                "ATCGGCGAGAACAAA\n" +
                ">Rosalind_4797\n" +
                "GACTTGCTCGTGGCTCCCGGAAGAGCGTTCTATTAAGCCCTAAAAAGG\n" +
                ">Rosalind_7672\n" +
                "TCGTCATGAT\n");
    }

    public void printTranslatedPeptide(String input) {
        List<FastaSequence> sequences = FastaReader.parseFastaInput(input);
        StringBuilder dna = new StringBuilder(sequences.get(0).getSequence());
        for (int i = 1; i < sequences.size(); ++i) {
            String intron = sequences.get(i).getSequence();
            int start = dna.indexOf(intron);
            while (start > -1) {
                dna.delete(start, start + intron.length());
                start = dna.indexOf(intron);
            }
        }
        System.out.println(RNA_TRANSLATOR.translateDnaToPeptide(dna.toString()));
    }
}
